/*********************
* Author:Dzlua
* QQ:505544956
* time:2016/09/10
*/
#include "Split.h"
#include "Log.h"

EDUI_NAMESPACE_BEGIN

Split::Split(const char* text, const char* split)
{
    if (text){
        m_text = text;
    }
    if (split){
        m_split = split;
    }
    m_bend = false;
}

Split::~Split()
{}

Split::Attribute* Split::First()
{
    if (m_bend) return 0;
    m_pos = m_text.Find(m_split);
    if (-1 == m_pos){
        m_attr.value = m_text;
        m_bend = true;
        return &m_attr;
    }
    String str = m_text.Left(m_pos);

    m_attr.value = m_text.Left(m_pos);
    
    return &m_attr;
}

Split::Attribute* Split::Next()
{
    if (m_bend) return 0;
    if (m_text.GetLength() <= m_pos + 1) return 0;
    
    int pos = m_pos;
    m_pos = m_text.Find(m_split, m_pos + 1);
    if (-1 == m_pos){
        m_attr.value = m_text.Right(m_text.GetLength() - pos - 1);
        m_bend = true;
        return &m_attr;
    }

    String str = m_text.Left(m_pos);

    m_attr.value = str.Right(m_pos - pos - 1);
  
    return &m_attr;
}

EDUI_NAMESPACE_END
